package cn.fbs.util;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;
import java.util.Base64;

public class RequestUtils {

  public static String getUserName(HttpServletRequest request) {
    String sessionId = request.getHeader("sessionId");
    sessionId = new String(Base64.getDecoder().decode(sessionId));
    JSONObject jsonObject = JSONObject.parseObject(sessionId);
    String userId = jsonObject.get("userId").toString();
    String userName = jsonObject.get("userName").toString();
    return userName;
  }

  public static Long getUserId(HttpServletRequest request) {
    String sessionId = request.getHeader("sessionId");
    sessionId = new String(Base64.getDecoder().decode(sessionId));
    JSONObject jsonObject = JSONObject.parseObject(sessionId);
    String userId = jsonObject.get("userId").toString();
    //        String userName = jsonObject.get("userName").toString();
    return Long.parseLong(userId);
  }
}
